package operation;

import car.Cars;

import java.util.Scanner;

public class DeleteVehicle implements IOperation {
    @Override
    public void work(Cars cars) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("1. 轿车   2. 客车   3. 卡车");
        System.out.print("请选择你要删除的车的类型: ");
        int type = scanner.nextInt();
        ShowVehicle showVehicle = new ShowVehicle();
        showVehicle.show(cars.getList(type));
        System.out.print("请输入你要删除的车的车牌号: ");
        String vehicleId = scanner.next();
        //删除车辆信息
        for (int i = 0; i < cars.getList(type).size(); i++) {
            if (cars.getList(type).get(i).getVehicleId().equals(vehicleId)) {
                cars.getList(type).remove(i);
                break;
            }
        }
        //删除数据库信息
        DBHelper.deleteVehicle(vehicleId);
        System.out.println("删除成功!");
    }
}
